package com.yungu.swift.system.sys.dao;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.system.sys.model.dto.SysWayDto;
import com.yungu.swift.system.sys.model.vo.ScanCodeWayInfoVo;
import com.yungu.swift.system.sys.model.vo.SimpleWayInfo;
import com.yungu.swift.system.sys.model.vo.SysWayInfoVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * SystemWayMapper数据库操作接口类
 **/

public interface SysWayMapper<T extends SysWayDto> extends IMapper<T> {

    List<SysWayDto> findWithOriginDest(Map<String, Object> params);

    PageList<SysWayDto> findWithOriginDest(Map<String, Object> params, PageBounds pageBounds);

    /**
     * 更新线路状态
     *
     * @param uuid
     * @param status
     * @return
     */
    @Update("update t_system_way set status=#{status} where uuid=#{uuid}")
    Integer updateStatus(@Param("uuid") String uuid, @Param("status") Integer status);

    /**
     * 开通关闭线路
     *
     * @param uuid
     * @param state
     * @return
     */
    @Update("update t_system_way set state=#{state} where uuid=#{uuid}")
    Integer updateState(@Param("uuid") String uuid, @Param("state") Integer state);

    /**
     * 统计正在使用的线路包该起&终点
     *
     * @param paras
     * @return
     */
    @Select("select count(0) from t_system_way where (origin_site_uuid=#{originSiteUuid} or dest_site_uuid=#{destSiteUuid}) and state=#{state}")
    Integer countExistedWaysByPointSiteState(Map paras);

    /**
     * 统计正在使用的线路包该起&终点
     *
     * @param paras
     * @return
     */
    @Select("select count(0) from t_system_way where (origin_site_uuid=#{originSiteUuid} or dest_site_uuid=#{destSiteUuid}) and status=#{status}")
    Integer countExistedWaysByPointSiteStatus(Map paras);

    /**
     * 更新小件状态
     *
     * @param uuid
     * @param status
     * @return
     */
    @Update("update t_system_way set parcel_status=#{status} where uuid=#{uuid}")
    Integer updateParcelStatus(@Param("uuid") String uuid, @Param("status") Integer status);

    /**
     * 获取小件规则
     * @param param
     * @return
     */
    SysWayInfoVo getParcelRule(Map<String, Object> param);

    /**
     * 获取所有线路名称
     * @param param
     * @return
     */
    List<SimpleWayInfo> getWayInfo(Map<String, Object> param);

    /**
     * 线路信息模糊查询
     * @param param
     * @return
     */
    List<SimpleWayInfo> fuzzyQueryByName(Map<String, Object> param);

    List<ScanCodeWayInfoVo> getScanCodeWayInfo(@Param("driverUuid") String driverUuid);
}